package com.jcb.showcase.graphic;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import com.jcb.showcase.R;

public class BoxButton   extends View {
String labelBox ;
Boolean active ;
Paint paint = new Paint();
//custom:label="Blue"


  

	public Boolean isActive() {
	return active;
}

public void setActive(Boolean active) {
	this.active = active;
}

	public String getLabelBox() {
	return labelBox;
}

public void setLabelBox(String labelBox) {
	this.labelBox = labelBox;
}

	public BoxButton(Context context) {
		super(context);
	}

	public BoxButton(Context context, AttributeSet attrs)
	{
	    super(context, attrs);
	    TypedArray a=context.obtainStyledAttributes(attrs, R.styleable.BoxButton);
	    labelBox = a.getString(R.styleable.BoxButton_labelBox);
	    if (labelBox == null ) labelBox = "Test" ;  
	    active  = a.getBoolean(R.styleable.BoxButton_active, true);	    
	    a.recycle();
	}
	
	public BoxButton(Context context, AttributeSet attrs, int defStyle) {
	      super(context, attrs, defStyle);
	      //this(context, attrs);	      
		    TypedArray a=context.obtainStyledAttributes(attrs, R.styleable.BoxButton);
		    labelBox = a.getString(R.styleable.BoxButton_labelBox);
		    if (labelBox == null ) labelBox = "Test" ;  
		    active  = a.getBoolean(R.styleable.BoxButton_active, true);
		    if (active == null) active = true ;
		    a.recycle();		   	      
	      //--- Additional custom code --
	   }
	
	


    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int space = 50 ;
        
        if (active) {
	        setBackgroundColor(0x00FFFFFF );
	        paint.setStyle(Paint.Style.STROKE);
	        paint.setStrokeWidth(3);
	        paint.setColor(Color.DKGRAY);
	        canvas.drawRect(space, space, this.getWidth()-space, this.getHeight()-space , paint);
        }
        else {
	        //setBackgroundColor(0x00FFFFFF );
	        paint.setStyle(Paint.Style.FILL);
	        paint.setColor(Color.DKGRAY);
	        Bitmap bmp;
	        bmp = BitmapFactory.decodeResource(getResources(), R.drawable.blue_padlock);
	        //Picture.
	        canvas.drawRect(space, space, this.getWidth()-space, this.getHeight()-space , paint);
	        int space2 = space + 5 ;
	        RectF dst = new RectF(space2 , space2, this.getWidth()-space2, this.getHeight()-space2);

	        canvas.drawBitmap(bmp, null, dst, paint);
      	
	        /*
	        Resources res = getResources();
	        Bitmap bitmap = BitmapFactory.decodeResource(res, R.drawable.your_image);
	       Then make the bitmap mutable and create a canvas over it:

	       Canvas canvas = new Canvas(bitmap.copy(Bitmap.Config.ARGB_8888, true));
	        */
	        
        }

        
          

        if (active) {
	        paint.setStrokeWidth(0);
	        paint.setColor(Color.BLACK);
	        canvas.drawText(labelBox,space +  20, space + 50, paint);        
        }
        	
        
//        ShapeDrawable mDrawables ;
//        RectF   inset = new RectF(space, space, this.getWidth()-space, this.getHeight()-space);
//        float[] outerR = new float[] { 12, 12, 12, 12, 0, 0, 0, 0 };
//        float[] innerR = new float[] { 12, 12, 0, 0, 12, 12, 0, 0 };
//        mDrawables = new ShapeDrawable(new RoundRectShape(outerR, inset,innerR));
//        mDrawables.getPaint().setColor(Color.rgb(240, 128, 128));  
//        //mDrawables.getPaint().setStyle(Paint.Style.FILL_AND_STROKE);  
        
        //mDrawables.draw(canvas);
        //canvas.drawRoundRect(inset, outerR, innerR, p) ;
        //canvas.
        //canvas.drawArc(oval, 0, 36 * 10, true, p);
    }
		
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        setMeasuredDimension(200, 200);
    }
        
    
}
